define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mechanism/usersignup/index' + location.search,
                    add_url: 'mechanism/usersignup/add',
                    edit_url: 'mechanism/usersignup/edit',
                    del_url: 'mechanism/usersignup/del',
                    multi_url: 'mechanism/usersignup/multi',
                    import_url: 'mechanism/usersignup/import',
                    table: 'mechanism_usersignup',
                    adminuth_url:'mechanism/usersignup/adminuth',
                    gongxinauth_url:'mechanism/usersignup/gongxinauth',
                    mechanismauth_url:'mechanism/usersignup/mechanismauth',

                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                      //  {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                     //   {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'id_card', title: __('Id_card'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'card_front_image', title: __('Card_front_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'card_back_image', title: __('Card_back_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'sex', title: __('Sex'), searchList: {"男":__('男'),"女":__('女')}, formatter: Table.api.formatter.normal},
                        // {field: 'pinyin', title: __('Pinyin'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'oldname', title: __('Oldname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'minzu', title: __('Minzu'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'jiguan', title: __('Jiguan'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'last_image', title: __('Last_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'mianmao', title: __('Mianmao'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'xueli', title: __('Xueli'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'major', title: __('Major'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'school', title: __('School'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'biye_school', title: __('Biye_school'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'comeinschool', title: __('Comeinschool'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'youbian', title: __('Youbian'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                     //   {field: 'mobile', title: __('Mobile'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'school_url', title: __('School_url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        // {field: 'chuanzhen', title: __('Chuanzhen'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'email', title: __('Email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                         {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user_check_id', title: __('User_check_id')},
                        // {field: 'courses_category_id', title: __('Courses_category_id')},
                        // {field: 'mechanism_category_topid', title: __('Mechanism_category_topid')},
                        // {field: 'mechanism_category_id', title: __('Mechanism_category_id')},
                        {field: 'mechanism_category_zhuanye', title: __('Mechanism_category_zhuanye'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'mechanism_category_jibie', title: __('Mechanism_category_jibie'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                         {field: 'user_check_name', title: __('机构名称'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'examination_message_name', title: __('Examination_message_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'examination_message_id', title: __('Examination_message_id')},
                        // {field: 'examination_mechanismplan_id', title: __('Examination_mechanismplan_id')},
                        {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'paytype', title: __('Paytype'), operate: 'LIKE'},
                        // {field: 'method', title: __('Method'), operate: 'LIKE'},
                        {field: 'transactionid', title: __('Transactionid'), operate: 'LIKE'},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'paystate', title: __('Paystate'), searchList: {"0":__('Paystate 0'),"1":__('Paystate 1')}, formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'step', title: __('Step'), searchList: {"待支付":__('待支付'),"已报名":__('已报名'),"平台审核通过":__('平台审核通过'),"工信部审核通过":__('工信部审核通过'),"平台拒绝":__('平台拒绝'),"工信部拒绝":__('工信部拒绝'),"待考试":__('待考试'),"考试结束":__('考试结束'),"派发证书":__('派发证书')}, formatter: Table.api.formatter.normal},
                       // {field: 'courses_category_name', title: __('Courses_category_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [

                                {
                                    name: 'adminuth',
                                    text: __('审核'),
                                    icon: '',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url:'mechanism/usersignup/adminuth',
                                    visible:function(row){//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if(row.paystate==1){

                                            if(row.groupIds==1 && row.step=='已支付'){
                                                return true;//显示
                                            }

                                        }else{
                                            return false;//隐藏
                                        }
                                    },

                                    refresh:true
                                },

                                {
                                    name: 'gongxinauth',
                                    text: __('审核'),
                                    icon: '',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url:'mechanism/usersignup/gongxinauth',
                                    visible:function(row){//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if(row.paystate==1){

                                            if(row.groupIds==7  && row.step=='平台审核通过'){

                                                return true;//显示
                                            }

                                        }else{
                                            return false;//隐藏
                                        }
                                    },

                                    refresh:true
                                },

                                {
                                    name: 'mechanismauth',
                                    text: __('审核'),
                                    icon: '',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url:'mechanism/usersignup/mechanismauth',
                                    visible:function(row){//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if(row.paystate==1){

                                            if(row.groupIds==8  && row.step=='工信部审核通过'){

                                                return true;//显示
                                            }

                                        }else{
                                            return false;//隐藏
                                        }
                                    },

                                    refresh:true
                                },
                                {
                                    name: 'mechanismauth',
                                    text: __('审核'),
                                    icon: '',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url:'mechanism/usersignup/mechanismauth',
                                    visible:function(row){//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if(row.paystate==1){

                                            if(row.groupIds==7  && row.step=='平台审核通过'){

                                                return true;//显示
                                            }

                                        }else{
                                            return false;//隐藏
                                        }
                                    },

                                    refresh:true
                                },



                            ],

                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        adminuth: function () {
            Controller.api.bindevent();
        },
        gongxinauth: function () {
            Controller.api.bindevent();
        },
        mechanismauth: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
